def to_camel_case(word):  
    if not word:  
        return word  
    first, *rest = word.split('_')  
    return first + ''.join(x.capitalize() for x in rest)

def convert_to_camel_case(instance):  
    """将模型实例的字段名从下划线转换为驼峰，并返回新字典。"""  
    camel_case_dict = {}
    if isinstance(instance, dict):
        for key in instance.keys():
            camel_case_name = to_camel_case(key)
            camel_case_dict[camel_case_name] = instance[key]
    else:
        print("dir(instance)==", dir(instance) )
        return instance
        if not "_meta" in dir(instance):
            return instance
        for field in instance._meta.get_fields():  
            if field.name not in ['id', 'pk']:  # 排除 Django 自动添加的字段  
                camel_case_name = to_camel_case(field.name)  
                camel_case_dict[camel_case_name] = getattr(instance, field.name)  
    return camel_case_dict